import { menu } from "../../decorator";
import baseShap from "./base/baseShap";

const { ccclass, property } = cc._decorator;

@ccclass
@menu(__filename)
export default class shapPolygon extends baseShap {
    @property
    _points: cc.Vec2[] = [cc.v2(-50, -50), cc.v2(50, -50), cc.v2(50, 50), cc.v2(-50, 50)]
    @property({
        tooltip: '多边形顶点数组(至少三个)',
        type: [cc.Vec2]
    })
    get points() { return this._points };
    set points(value) {
        this._points = value;
        this.node && this.node.emit('points-change');
    };

    contains(nodePoint: cc.Vec2): boolean {
        return cc.Intersection.pointInPolygon(nodePoint.sub(this.offset), this._points);
    }
}
